package controllers;

import windows.GameConsole;
import Chat.A_Chat_Client;

public class Config {
	public boolean sonar;
	public boolean radar;
	public boolean infrared;
	public String selectedWeapon;
	public String selectedTarget;
	public static Config config = null;
	public int speed;// speed van het schip in integers
	public double PercentageLeft;
	public String nickname;
	public String ownBoat;
	public A_Chat_Client chatClient;
	public String[] weaponsOnShip = {"Select Weapon"};
	public String[] weaponsOnDestroyer = {"Missile", "Canonball", "BulletCloud", "SoundBuoy", "Chaff"};
	public String[] weaponsOnFrigate = {"Canonball", "Torpedo", "BulletCloud", "SoundBuoy", "Chaff"};
	public String[] weaponsOnHunter = {"Missile", "Torpedo", "BulletCloud", "SoundBuoy", "Chaff"};
	public String[] weaponsOnSubmarine = {"Torpedo"};
	public int scale;


		
	protected Config(){};
	public static Config getConfig(){
		if(config == null){
			config = new Config();
		}
		return config;
	}
	
	public void setSpeed(int speedPercentage)
	{
		if(ownBoat == "Destroyer")
		{
			speed = 12;//in m/s
		}
		else if (ownBoat == "Frigate") 
		{
			speed = 15;//in m/s
		}
		else if(ownBoat == "Hunter")
		{
			speed = 21;//in m/s
		}
		else if(ownBoat == "Submarine")
		{
			speed = 12;//in m/s
		}
		double product = speedPercentage / 100;
		
		if(PercentageLeft<=40)
		{
			product = product/4;
		}
		speed = (int)(speed * product);
	}
	
	public void setWeaponsOnShip(String ship)
	{			
		if(ship == "Destroyer")
		{
			Config.getConfig().weaponsOnShip = weaponsOnDestroyer;
		}
		else if (ship == "Frigate") 
		{
			Config.getConfig().weaponsOnShip = weaponsOnFrigate;
		}
		else if(ship == "Hunter")
		{
			Config.getConfig().weaponsOnShip = weaponsOnHunter;
		}
		else if(ship == "Submarine")
		{
			Config.getConfig().weaponsOnShip = weaponsOnSubmarine;
		}
		int arraylenth = weaponsOnShip.length;
		if(PercentageLeft==90)
		{
				for(int i=0;i<=arraylenth;i++)
				{
					if(weaponsOnShip[i] == "Torpedo")
					{
						String temp = weaponsOnShip[i];
						weaponsOnShip[i] = weaponsOnShip[arraylenth];
						weaponsOnShip[arraylenth] = temp + "(Lost)";
					}
				}
				//torpedo
				if(PercentageLeft==70)
				{
					for(int i=0;i<=arraylenth;i++)
					{
						if(weaponsOnShip[i] == "Cannon")
						{
							String temp = weaponsOnShip[i];
							weaponsOnShip[i] = weaponsOnShip[arraylenth];
							weaponsOnShip[arraylenth] = temp + "(Lost)";
						}
					}
					//cannon
					if(PercentageLeft==50)
					{
						for(int i=0;i<=arraylenth;i++)
						{
							if(weaponsOnShip[i] == "Goal keeper")
							{
								String temp = weaponsOnShip[i];
								weaponsOnShip[i] = weaponsOnShip[arraylenth];
								weaponsOnShip[arraylenth] = temp + "(Lost)";
							}
						}
						//goalkeeper
						if(PercentageLeft==40)
						{
							for(int i=0;i<=arraylenth;i++)
							{
								if(weaponsOnShip[i] == "Missile")
								{
									String temp = weaponsOnShip[i];
									weaponsOnShip[i] = weaponsOnShip[arraylenth];
									weaponsOnShip[arraylenth] = temp + "(Lost)";
								}
							}
							//missile
						}
					}
				}
			}
		}
	}
